package com.ysd.lis.controller;


import com.ysd.common.Result;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.WkFile;
import com.ysd.lis.request.WkFolderParam;
import com.ysd.lis.service.WkFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 员工表
 * 前端控制器
 * </p>
 *
 * @author peng
 * @since 2024-03-04
 */
@Api(tags = "文件管理-文档")
@RestController
@RequestMapping("/api/wk/WkFile")
public class WkFileController extends BaseController {

    @Autowired
    WkFileService wkFileService;
    @ApiOperation("上传检测标准附件")
    @PostMapping("/uploadFiles")
    public Result uploadFiles(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request) throws IOException {
        return  wkFileService.uploadFiles(file,request);
    }

    @ApiOperation("查询")
    @GetMapping("/findFolderAndFileList")
    public Result findFolderAndFileList(WkFolderParam param){
        return wkFileService.findFolderAndFileList(param);
    }
    @ApiOperation("通过code查询文件")
    @GetMapping("/findFolderAndFileListByCode")
    public Result findFolderAndFileListByCode(WkFolderParam param){
        return wkFileService.findFolderAndFileListByCode(param);
    }
    @ApiOperation("根据详情id删除详情数据")
    @PostMapping("/deleteFile")
    public Result deleteFile(@RequestBody WkFile file) {
        return wkFileService.deleteFile(file);
    }
    @ApiOperation("修改")
    @PostMapping("/editFile")
    public Result editFile(@RequestBody WkFile file) {
        return wkFileService.editFile(file);
    }
    @ApiOperation("新增")
    @PostMapping("/copyFile")
    public Result copyFile(@RequestBody WkFile file) throws IOException {
        return  wkFileService.copyFile(file);
    }

    /**
     * 下载附件
     *
     * @param id
     * @param response
     */
    @GetMapping("/downWkFile")
    public void downWkFile(@RequestParam String id, HttpServletResponse response) {
        wkFileService.downWkFile(id,response);
    }

    @GetMapping("/viewWkFile")
    public void viewWkFile(String id, HttpServletResponse response) {
        wkFileService.viewWkFile(id,response);

    }
}
